<?php
    $xtpl_edit      = new XTemplate("view/comment/edit.htm");
    
    $title      = "Sửa bài bình luận";
    $id         = $_GET['id'];    
    
    $query  = "SELECT * FROM comment WHERE id_cm='" . $id . "'";
    $re     = mysql_query($query);
    $row    = mysql_fetch_array($re);
    
    $sql_p  = "SELECT * FROM product WHERE id_p='" . $row['product_id'] . "'";
    $re_p   = mysql_query($sql_p);
    $row_p  = mysql_fetch_array($re_p);
    
    $sql_m  = "SELECT * FROM member WHERE id_m='" . $row['user_id'] . "'";
    $re_m   = mysql_query($sql_m);
    $row_m  = mysql_fetch_array($re_m);
    
    $xtpl_edit      -> assign('milkname', $row_p['milkname']);
    $xtpl_edit      -> assign('username', $row_m['username']);
    $xtpl_edit      -> assign('date', $row['date']);
    $xtpl_edit      -> assign('content', $row['content']);
    
    if(isset($_POST['submit'])){
        if($_POST['content'] != NULL){
            $sql    = "UPDATE comment SET content='" . $_POST['content'] . "'
                       WHERE    id_cm='" . $id . "'";
            $result = mysql_query($sql);
            if($result){
                $error  = "Đã sửa thông tin thành công";
            }
        }
        else{
            $error  = "Bạn chưa điền đầy đủ thông tin";
        }
    }
    
    if(isset($_POST['cancel'])){
        header("location:index.php?page=comment");
    }
    
    $xtpl_edit      -> assign('error', $error);
    $xtpl_edit      -> parse("EDIT");
    $content        = $xtpl_edit -> text("EDIT");
?>